<template>
  <div :class="containerClasses">
    <div :class="spinnerClasses"></div>
    <span v-if="text" class="ml-2 text-gray-600">{{ text }}</span>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'

interface Props {
  size?: 'sm' | 'md' | 'lg' | 'xl'
  text?: string
  center?: boolean
  overlay?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  size: 'md',
  center: false,
  overlay: false
})

const containerClasses = computed(() => {
  const baseClasses = 'flex items-center justify-center'
  
  const centerClasses = props.center ? 'w-full h-full' : ''
  const overlayClasses = props.overlay ? 'fixed inset-0 bg-white bg-opacity-75 z-50' : ''
  
  return [baseClasses, centerClasses, overlayClasses].join(' ')
})

const spinnerClasses = computed(() => {
  const baseClasses = 'animate-spin rounded-full border-b-2 border-blue-500'
  
  const sizeClasses = {
    sm: 'h-4 w-4',
    md: 'h-6 w-6',
    lg: 'h-8 w-8',
    xl: 'h-12 w-12'
  }
  
  return [baseClasses, sizeClasses[props.size]].join(' ')
})
</script>
